package com.jtpay.sdk.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.jtpay.sdk.R;
import com.jtpay.sdk.jtpay.constant.PayConstant;
import com.jtpay.sdk.util.JftConstants;
import com.jtpay.sdk.util.JftLogUtil;

public class PlatformConfigActivity extends BaseActivity {
    private static final String JFT = "jft";
    private static final String YHB = "yhb";
    private static final String YZF = "yzf";
    private static final String WSF = "wsf";
    private static final String QAO = "qao";
    private static final String PRICE = "10";
    private String mTitle;
    private String mHostName;
    private String mComKey;
    private String mUserCode;
    private String mPrice = PRICE;
    private EditText mPriceText;
    private TextView mUserCodeText;
    private TextView mComKeyText;
    private Button mPayTypeBtn;

    private void defaultConfig(String title) {
        switch (title) {
            case "竣付通":
                mHostName = JFT;
                JftConstants.setJunFuTongUrlQuery(PayConstant.DEFAULT_PAY_URL_JFT);
                break;
            case "亿汇宝":
                mHostName = YHB;
                JftConstants.setJunFuTongUrlQuery(PayConstant.DEFAULT_PAY_URL_YHB);
                break;

            case "亿支付":
                mHostName = YZF;
                JftConstants.setJunFuTongUrlQuery(PayConstant.DEFAULT_PAY_URL_YZF);
                break;
            case "旺实富":
                mHostName = WSF;
                JftConstants.setJunFuTongUrlQuery(PayConstant.DEFAULT_PAY_URL_WSF);
                break;
            case "旗翱":
                mHostName = QAO;
                break;
            default:
                mHostName = JFT;
                JftConstants.setJunFuTongUrlQuery(PayConstant.DEFAULT_PAY_URL_JFT);
                break;

        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_platform_config);
        mTitle = getIntent().getExtras().getString(JftConstants.JUN_FU_TONG_PLAT_FORM_NAME, "");
        mUserCode = getIntent().getExtras().getString(JftConstants.JUN_FU_TONG_USER_CODE, "");
        mComKey = getIntent().getExtras().getString(JftConstants.JUN_FU_TONG_COM_KEY, "");
        JftLogUtil.log("PlatformConfigActivity onCreate title = " + mTitle);
        defaultConfig(mTitle);
        initViews();
    }

    private void initViews() {
        mPriceText = (EditText) findViewById(R.id.text_price);
        mPriceText.setText(mPrice);
        mUserCodeText = (TextView) findViewById(R.id.text_user_code);
        mUserCodeText.setText(mUserCode);
        mComKeyText = (TextView) findViewById(R.id.text_com_key);
        mComKeyText.setText(mComKey);
        mPayTypeBtn = (Button) findViewById(R.id.btn_pay_type);
        mPayTypeBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String price = mPriceText.getText().toString();
                String userCode = mUserCodeText.getText().toString();
                String comKey = mComKeyText.getText().toString();
                String hostName = mHostName;
                String title = mTitle;
                PayTypeActivity.startActivity(PlatformConfigActivity.this, price, userCode, comKey, hostName, title);
            }
        });
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setTitle(mTitle);
        toolbar.setTitleTextColor(Color.RED);
    }
}